package com.ggshily.game.model.ms3d
{
	import flash.utils.ByteArray;
	
	public class Ms3d_joint
	{
		public var flags : int;
		public var name : String;                                         // char[32]
		public var parentName : String;                                   // char[32]
		public var rotation : Array = new Array(3);
		public var position : Array = new Array(3);
		public var numKeyFramesRot : int;
		public var numKeyFramesTrans : int;
		public var keyFramesRot : Array;
		public var keyFramesTrans : Array;
		
		public var tangents : Array;
		
		// used for rendering
		public var parentIndex : int;
		public var matLocalSkeleton : Array = [[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]];   //float[3][4]
		public var matGlobalSkeleton : Array = [[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]];
		public var matLocal : Array = [[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]];
		public var matGlobal : Array = [[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]];
		
		public function Ms3d_joint(bytes : ByteArray = null)
		{
			if(bytes)
			{
				flags = bytes.readUnsignedByte();
				name = bytes.readUTFBytes(32);
				parentName = bytes.readUTFBytes(32);
				rotation[0] = bytes.readFloat();
				rotation[1] = bytes.readFloat();
				rotation[2] = bytes.readFloat();
				position[0] = bytes.readFloat();
				position[1] = bytes.readFloat();
				position[2] = bytes.readFloat();
				
				numKeyFramesRot = bytes.readShort();
				numKeyFramesTrans = bytes.readShort();
				
				keyFramesRot = new Array(numKeyFramesRot);
				for(var i : int = 0; i < numKeyFramesRot; i++)
				{
					keyFramesRot[i] = new Ms3d_keyframe_rot(bytes);
				}
				keyFramesTrans = new Array(numKeyFramesTrans);
				for(i = 0; i < numKeyFramesTrans; i++)
				{
					keyFramesTrans[i] = new Ms3d_keyframe_pos(bytes);
				}
			}
		}
	}
}